#include <bits/stdc++.h>
using namespace std;

#define ONLINE_JUDGE

#ifndef ONLINE_JUDGE
#define dbg(x...)                             \
	{                                         \
		cerr << "\033[32;1m" << #x << " -> "; \
		err(x);                               \
	}
void err()
{
	cerr << "\033[39;0m" << endl;
}
template <typename T, typename... A>
void err(T a, A... x)
{
	cerr << a << ' ';
	err(x...);
}
#else
#define dbg(...)
#endif

typedef long long LL;

const int N = 1e5 + 50;
const int M = 366;

typedef pair<int, int> P;

LL dp[M][M];
LL dp2[N][M];

int a[N], n;

int B;

int l[M], r[M];
int belong[N];
int bucket[M][M][M];

LL merg(int b[], int c[], int n, int m)
{

	int nn = 0, mm = 0, bnum = 0;
	LL res = 0, bsum = 0;
	while (nn < n && mm < m)
	{
		if (b[nn + 1] < c[mm + 1])
		{
			bsum += b[++nn];
			++bnum;
		}
		else
		{
			res += c[++mm] * bnum - bsum;
		}
	}
	while (mm < m)
		res += c[++mm] * bnum - bsum;
	// dbg(res);
	return res;
}

LL calc(P p1, P p2)
{
	int bid = belong[p1.first],
		cid = belong[p2.first];
	int *b = bucket[bid][p1.second - p1.first + 1],
		*c = bucket[cid][p2.second - p2.first + 1];
	int n = p1.second - p1.first + 1,
		m = p2.second - p2.first + 1;
	// dbg(p1.first, p1.second, p2.first, p2.second);
	// for (int i = 1; i <= n; ++i)
	// 	dbg(i, b[i]);
	// for (int j = 1; j <= m; ++j)
	// 	dbg(j, c[j]);

	LL res = merg(b, c, n, m) + merg(c, b, m, n);
	// dbg(res);
	return res;
}

inline LL solve(int i, int j)
{
	if (i == 0 || j == 0)
		return 0;
	int ii = belong[i] - 1, jj = belong[j] - 1;
	LL res = dp2[i][jj] + dp2[j][ii] - dp[ii][jj] + calc(make_pair(l[belong[i]], i), make_pair(l[belong[j]], j));
	// dbg(i, j, ii, jj, res);
	return res;
}

inline LL solve(P p1, P p2)
{
	LL res = solve(p1.second, p2.second) - solve(p1.first - 1, p2.second) - solve(p1.second, p2.first - 1) + solve(p1.first - 1, p2.first - 1);
	return res;
}

LL check(P p1, P p2)
{
	LL res = 0;
	for (int i = p1.first; i <= p1.second; ++i)
		for (int j = p2.first; j <= p2.second; ++j)
		{
			res += abs(a[i] - a[j]);
		}
	return res;
}

int main(int argc, char const *argv[])
{
	int q;
	scanf("%d%d", &n, &q);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);

	int C = (int)sqrt(n) + 1, B = (n + C - 1) / C;
	// dbg(B, C);
	for (int i = 1; i <= B; ++i)
	{
		l[i] = r[i - 1] + 1;
		r[i] = min(n, l[i] + C - 1);
		int siz = r[i] - l[i] + 1;
		for (int j = l[i]; j <= r[i]; ++j)
			belong[j] = i;
		set<int> S;
		for (int j = 1; j <= siz; ++j)
		{
			S.insert(a[l[i] - 1 + j]);
			int t = 0;
			for (int x : S)
				bucket[i][j][++t] = x;
		}
		// dbg(i, l[i], r[i]);
	}

	for (int i = 1; i <= B; ++i)
		for (int j = 1; j <= B; ++j)
		{
			dp[i][j] = dp[i][j - 1] + dp[i - 1][j] - dp[i - 1][j - 1] + calc(make_pair(l[i], r[i]), make_pair(l[j], r[j]));
			// dbg(i, j, dp[i][j]);
		}

	for (int i = 1; i <= n; ++i)
		for (int jj = 1; jj <= B; ++jj)
		{
			int ii = belong[i] - 1;
			dp2[i][jj] = dp[ii][jj] +
						 (dp2[i][jj - 1] - dp[ii][jj - 1]) + calc(make_pair(l[belong[i]], i), make_pair(l[jj], r[jj]));
			// dbg(i, jj, dp2[i][jj]);
		}

	// dp[][]
	for (int kk = 0; kk < q; ++kk)
	{
		P p1, p2;
		scanf("%d%d%d%d", &p1.first, &p1.second, &p2.first, &p2.second);
		LL ans = solve(p1, p2);
		printf("%lld\n", ans);
		// dbg(check(p1, p2));
		if (check(p1, p2) != ans)
		{
			// dbg(check(p1, p2));
			puts("FUCK");
			return 0;
		}
	}

	return 0;
}